<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\View;
use Illuminate\Support\Facades\Storage;

class HtmlController extends Controller
{
    //
    public function index($dir, $dir2 = '', $file = '')
    {
        if ($dir2 != '' && $file != '')
            $dir = $dir . '/' . $dir2;
        if ($file == '')
            $file = $dir2;
        $file      = strstr ($file, '.', true) !== false ? strstr ($file, '.', true) : $file;
        $view_path = $dir . '/' . $file;
        if (View::exists ($view_path)) {
            //
            $contents = view ($view_path);
            Storage::disk ('publics')->put ('dist/html/' . $view_path . '.html', $contents);
            $files = Storage::disk ('publics')->allFiles ('html/' . $dir);
            foreach ($files as $item) {
                Storage::disk ('publics')->delete ('dist/' . $item);
                Storage::disk ('publics')->copy ($item, 'dist/' . $item);
            }

            return $contents;
        } else {
            dd ('文件视图：' . $view_path . '不存在');
        }
    }
}
